// JavaScript Document
$(function () {
	initModify();
	//提交
	$(".submit").on("click",function(){
		checkModify();
	});
});
//初始化
function initModify(){
	/*CKEDITOR.replace( 'crcseContent' , { height: '240px', 
		width: '480px',
		toolbar: [[ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo', 'Bold',
	                    'Italic',"Format","FontSize","TextColor" ,"CodeSnippet","Table"]],
		extraPlugins: 'codesnippet',
		uiColor: '#f3f3f3'
		//codeSnippet_theme: 'zenburn'
	} );*/
	getInfo(getQueryString("id"));	
}
//获取详情
function getInfo(id){
	var str = 'criglUuid='+encodeURIComponent(id);
	getOData(str,"coreIntegral/views",{fn:function(oData){
		if(oData.code == 1) {
			$(".criglName").val(oData.data.criglName || "");
			$(".criglScore").val(oData.data.criglScore || "");
			$(".criglDesc").val(oData.data.criglDesc || "");			
			/*CKEDITOR.instances.crcseContent.setData(oData.data.crcseContent);*/
		} else {
			alert(data.errMsg);
		}
	}});
}
//检查提交
function checkModify(){
	if($.trim($(".criglName").val()) == ""){
		alert("触发事件不能为空，请填写完再提交！");
		$(".criglName").focus();
		return false;
	}
	if($.trim($(".criglScore").val()) == ""){
		alert("所得收益不能为空，请填写完再提交！");
		$(".criglScore").focus();
		return false;
	}
	if($.trim($(".criglDesc").val()) == ""){
		alert("积分说明不能为空，请填写完再提交！");
		$(".criglDesc").focus();
		return false;
	}
	
	var r=confirm("是否确认修改？");
	if (r==true){
		var msgObject = parent.layer.msg('处理中，请等待……', {
			icon: 16,
			shade: 0.4,
			time: waitImgTime //（如果不配置，默认是3秒）
		}, function(index){
			//do something
			parent.layer.close(index);
		});
		Modify(msgObject);
	}
}
//提交
function Modify(msgObject){
	var criglUuid = getQueryString("id");
	var criglName = $(".criglName").val();
	var criglScore = $(".criglScore").val();
//	var crcseContent = CKEDITOR.instances.crcseContent.getData();
	var criglDesc = $(".criglDesc").val();	
	var str = 'criglUuid='+encodeURIComponent(criglUuid)+'&criglName='+encodeURIComponent(criglName)+'&criglScore='+encodeURIComponent(criglScore)+'&criglDesc='+encodeURIComponent(criglDesc);
	getOData(str,"coreIntegral/update/coreIntegral",{
		fn:function(oData){
			window.parent.refreshList();
			alert("修改成功！");		
		},
		fnerr:function(oData){
			parent.layer.close(msgObject);
		}
	});
}
function IsNum(num) {
	var reNum = /^\d*$/;
	if (reNum.test(num)) {
		return true;
	} else {
		if (num < 0) {
			alert("所得收益不能为负数！");
		} else {
			alert("所得收益必须为数字！");
		}
		return false;
	}
}  